package com.cableex.mmb_mtj_android_v1;

import android.app.Application;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.telephony.TelephonyManager;

/**
 * Created by ${Dota.Wang} on 2017/4/23.
 */
public class SystemInfo {
    private SharedPrenfenceUtil sp;
    private static SystemInfo instance;

    //进入的时候单例获取的参数
//    public String imei;
//    private String appName;
//    private String versionCode;
//    private String modelType;
//    private String memberId;


    public SystemInfo(Context ctx) {
        this.sp = SharedPrenfenceUtil.getInstance();
    }

    /**
     * 单例模式
     *
     * @return 唯一退出应用对象
     */
    public static SystemInfo getInstance(Context ctx) {
        if (null == instance) {
            synchronized (SystemInfo.class) {
                if (null == instance) {
                    instance = new SystemInfo(ctx);
                }
            }
        }
        return instance;
    }


    public static synchronized String getImei(Context var0){
        String imei ;
        if(var0 != null ) {
            imei =((TelephonyManager) var0.getSystemService(var0.TELEPHONY_SERVICE)).getDeviceId();
        }else {
            imei = "";
        }
        return imei;
    }

    public static synchronized String getAppName(Context var0, Application application){
        String appName = null;
        if(var0 != null) {
            try {
                PackageInfo pkg  = var0.getPackageManager().getPackageInfo(application.getPackageName(), 0);
                appName = pkg.applicationInfo.loadLabel(var0.getPackageManager()).toString();
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }
        }else {
            appName = "";
        }
        return appName;
    }

    public static synchronized String getVersionCode(Context var0, Application application){
        String versionCode = null;
        if(var0 != null ) {
            try {
                PackageInfo pkg  = var0.getPackageManager().getPackageInfo(application.getPackageName(), 0);
                versionCode= pkg.versionName;
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }
        }else {
            versionCode = "";
        }
        return versionCode;
    }

    public static synchronized String getModelType(Context var0){
        String modelType ;
        if(var0 != null ) {
            Build bd = new Build();
            modelType= bd.MODEL;
        }else {
            modelType = "";
        }
        return modelType;
    }


}
